#include "ver.h"
#include "main.h"

static uint8_t hardVersion = 0;    // 数字表示
const port_pin_t hardVerPort[] = {{VER_1_GPIO_Port,VER_1_Pin},
                                  {VER_2_GPIO_Port,VER_2_Pin},
                                  {VER_3_GPIO_Port,VER_3_Pin}
                                 };

static void Read_HardVer(void)
{
    int hardVer = 0;
    for(int i=0;i<sizeof(hardVerPort)/sizeof(port_pin_t);i++){
        if(HAL_GPIO_ReadPin(hardVerPort[i].port, hardVerPort[i].pin) == GPIO_PIN_RESET){
            hardVer |= (1<<i);
        }
    }
    hardVersion = hardVer;
}

uint8_t Get_HardVer(void)
{
    static uint8_t hardVerReadFlag = 0;
    if(hardVerReadFlag == 0){
        Read_HardVer();
        hardVerReadFlag = 1;
    }
    return hardVersion;

}

